home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / plnk081.zip / pilot-link.0.8.1 / memos.c < prev    next >
C/C++ Source or Header  |  1997-08-03  |  3KB  |  117 lines

  1. /* memos.c:  Translate Pilot Memos into e-mail format
  2.  *
  3.  * Copyright (c) 1996, Kenneth Albanowski
  4.  *
  5.  * This is free software, licensed under the GNU Public License V2.
  6.  * See the file COPYING for details.
  7.  */
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #include "pi-source.h"
  13. #include "pi-socket.h"
  14. #include "pi-memo.h"
  15. #include "pi-dlp.h"
  16.  
  17. int main(int argc, char *argv[])
  18. {
  19.   struct pi_sockaddr addr;
  20.   int db;
  21.   int sd;
  22.   int i;
  23.   struct PilotUser U;
  24.   int ret;
  25.   unsigned char buffer[0xffff];
  26.   char appblock[0xffff];
  27.   struct MemoAppInfo mai;
  28.  
  29.   if (argc < 2) {
  30.     fprintf(stderr,"usage:%s %s\n",argv[0],TTYPrompt);
  31.     exit(2);
  32.   }
  33.   if (!(sd = pi_socket(PI_AF_SLP, PI_SOCK_STREAM, PI_PF_PADP))) {
  34.     perror("pi_socket");
  35.     exit(1);
  36.   }
  37.     
  38.   addr.pi_family = PI_AF_SLP;
  39.   strcpy(addr.pi_device,argv[1]);
  40.   
  41.   ret = pi_bind(sd, (struct sockaddr*)&addr, sizeof(addr));
  42.   if(ret == -1) {
  43.     perror("pi_bind");
  44.     exit(1);
  45.   }
  46.  
  47.   ret = pi_listen(sd,1);
  48.   if(ret == -1) {
  49.     perror("pi_listen");
  50.     exit(1);
  51.   }
  52.  
  53.   sd = pi_accept(sd, 0, 0);
  54.   if(sd == -1) {
  55.     perror("pi_accept");
  56.     exit(1);
  57.   }
  58.  
  59.   /* Ask the pilot who it is. */
  60.   dlp_ReadUserInfo(sd,&U);
  61.   
  62.   /* Tell user (via Pilot) that we are starting things up */
  63.   dlp_OpenConduit(sd);
  64.   
  65.   /* Open the Datebook's database, store access handle in db */
  66.   if(dlp_OpenDB(sd, 0, 0x80|0x40, "MemoDB", &db) < 0) {
  67.     puts("Unable to open MemoDB");
  68.     dlp_AddSyncLogEntry(sd, "Unable to open MemoDB.\n");
  69.     exit(1);
  70.   }
  71.   
  72.   dlp_ReadAppBlock(sd, db, 0, (unsigned char *)appblock, 0xffff);
  73.   unpack_MemoAppInfo(&mai, (unsigned char *)appblock, 0xffff);
  74.  
  75.   for (i=0;1;i++) {
  76.       struct Memo m;
  77.       int attr;
  78.       int category;
  79.       int j;
  80.                                  
  81.       int len = dlp_ReadRecordByIndex(sd, db, i, buffer, 0, 0, &attr, &category);
  82.       if(len<0)
  83.           break;
  84.           
  85.       /* Skip deleted records */
  86.       if((attr & dlpRecAttrDeleted) || (attr & dlpRecAttrArchived))
  87.           continue;
  88.           
  89.     unpack_Memo(&m, buffer, len);
  90.     
  91.     printf("From your.pilot Tue Oct  1 07:56:25 1996\nReceived: Pilot@p by memo Tue Oct  1 07:56:25 1996\nTo: you@y\nDate: Thu, 31 Oct 1996 23:34:38 -0500\n");
  92.     printf("Subject: ");
  93.     printf("[%s] ", mai.category.name[category]);
  94.     for(j=0;j<40;j++) {
  95.         if((!m.text[j]) || (m.text[j] == '\n'))
  96.             break;
  97.         printf("%c",m.text[j]);
  98.     }
  99.     if(j==40)
  100.         printf("...\n");
  101.     else
  102.         printf("\n");
  103.     puts("");
  104.     puts(m.text);
  105.   }
  106.  
  107.   /* Close the database */
  108.   dlp_CloseDB(sd, db);
  109.  
  110.   dlp_AddSyncLogEntry(sd, "Read memos from Pilot.\n");
  111.  
  112.   pi_close(sd);  
  113.   
  114.   exit(0);
  115. }
  116.  
  117.